package cn.fangline.wo.service;

import cn.fangline.base.util.exception.BussinessException;
import cn.fangline.wo.mapper.ViewMapper;
import cn.fangline.wo.model.View;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by 抽离 on 2017/3/24 0024.
 */
@Service
public class ViewService {

    @Autowired
    private ViewMapper viewMapper;

    /**
     * 添加浏览房源记录
     * @param view
     * @throws BussinessException
     */
    public void addView(View view)throws BussinessException {
        if(view.getHouseId() == null){
            throw new BussinessException("参数异常");
        }
        View queryView = view.selectOne("house_id={0} AND create_user={1}", view.getHouseId(), view.getCreateUser());
        if(queryView == null){
            view.setCreateTime(new Date());
            view.insert();
        }
        else{
            queryView.setCreateTime(new Date());
            queryView.updateById();
        }
    }

     public List<View> findViewList(Long houseId)throws  BussinessException{
        if(houseId == null){
            throw  new BussinessException("参数错误");
        }
        return viewMapper.selectViewList(houseId);
     }

}
